﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _16_List集合集合lambda表达式与泛型委托
{
    internal class Program
    {
        static void Main(string[] args)
        {
            List<Student> socre = new List<Student>();

            socre.Add(new Student(1, "龙傲天", "Halcon",  95));
            socre.Add(new Student(1, "龙傲天", "CSharp",  80));
            socre.Add(new Student(1, "龙傲天", "运动控制 ", 70));

            socre.Add(new Student(2, "王德发", "Halcon", 75));
            socre.Add(new Student(2, "王德发", "CSharp", 56));
            socre.Add(new Student(2, "王德发", "运动控制 ", 65));

            socre.Add(new Student(3, "坤坤", "Halcon", 79));
            socre.Add(new Student(3, "坤坤", "CSharp", 76));
            socre.Add(new Student(3, "坤坤", "运动控制 ", 80));

            //求各个同学的 平均成绩 与 总成绩
            for (int i = 1; i <= 3; i++)
            {
                List<Student> student = socre.FindAll(t => t.Id == i);
                Console.WriteLine("{0}-总分:\t{1:0.00}", student[0].Name, student.Sum(t => t.Score));//求总成绩
                Console.WriteLine("{0}-平均分:\t{1:0.00}", student[0].Name, student.Average(t => t.Score));//求平均成绩
                Console.WriteLine("==================================================================");
            }

            //求全班同学的halcon平局分
            double AvgHaclon = socre.FindAll(t => t.Subject == "Halcon").Average(t => t.Score);
            Console.WriteLine("全班同学的Halcon平均分:{0:0.00}", AvgHaclon);
            Console.WriteLine("==================================================================");

            //求全班同学的CSharp平局分
            double AvgCSharp = socre.FindAll(t => t.Subject == "CSharp").Average(t => t.Score);
            Console.WriteLine("全班同学的CSharp平均分:{0:0.00}", AvgCSharp);
            Console.WriteLine("==================================================================");

            //找出低于60分的同学，打印输出
            Console.WriteLine("低于60分的同学:");
            socre.FindAll(t => t.Score < 60).ForEach(t => t.PrintInfo());
            Console.WriteLine("==================================================================");

            //查询学号为2的同学halcon考试成绩
            Console.Write("学号为2的同学halcon考试成绩:");
            Console.WriteLine(socre.Find(t => t.Id == 2 && t.Subject == "Halcon").Score);
            Console.WriteLine("==================================================================");

            //求halcon科目的最高分与最低分
            int max = socre.FindAll(t => t.Subject == "Halcon").Max(t => t.Score);
            int min = socre.FindAll(t => t.Subject == "Halcon").Min(t => t.Score);
            Console.WriteLine("Halcon科目的最高分:\t{0}", max);
            Console.WriteLine("Halcon科目的最低分:\t{0}", min);
            Console.WriteLine("==================================================================");

            Console.ReadKey();

        }
    }
}
